<template>
  <div class="dashboard">
    <el-card class="top">
      <div class="contain">
        <ul class="toal">
          <li>
            <div class="yuan">12</div>
            <div class="text">今日新增用户</div>
          </li>
          <li>
            <div class="yuan">1209</div>
            <div class="text">总用户量</div>
          </li>
          <li>
            <div class="yuan">1</div>
            <div class="text">新增试题</div>
          </li>
          <li>
            <div class="yuan">745</div>
            <div class="text">总试题量</div>
          </li>
          <li>
            <div class="yuan">0</div>
            <div class="text">总刷题量</div>
          </li>
          <li>
            <div class="yuan">0</div>
            <div class="text">人均刷题量</div>
          </li>
        </ul>
      </div>
    </el-card>
    <el-card class="box-card">
      <div ref="chart" style="height: 400px; " />
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'Dashboard',
  data() {
    return {
      data: []
    }
  },
  mounted() {
    const chart = echarts.init(this.$refs.chart)
    chart.setOption({
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      legend: {
        // type: 'scroll',
        orient: 'vertical',
        right: 120,
        top: 20,
        data: this.data.legendData
      },
      series: [
        {
          name: '姓名',
          type: 'pie',
          right: 350,
          radius: ['50%', '80%'],
          center: ['40%', '50%'],
          data: this.data.seriesData,
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
              backgroundColor: '#6f6f6f'
            },
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold',
              color: '#dfdfdf'
            }
          }
        }
      ]
    })
  },
  created() {
    this.data = this.genData(50)
  },
  methods: {
    genData(count) {
      // prettier-ignore
      const nameList = [
        '赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦', '章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马', '苗', '凤', '花', '方', '俞', '任', '袁', '柳', '酆', '鲍', '史', '唐', '费', '廉', '岑', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬', '安', '常', '乐', '于', '时', '傅', '皮', '卞', '齐', '康', '伍', '余', '元', '卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹', '姚', '邵', '湛', '汪', '祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈', '宋', '茅', '庞', '熊', '纪', '舒', '屈', '项', '祝', '董', '梁', '杜', '阮', '蓝', '闵', '席', '季', '麻', '强', '贾', '路', '娄', '危'
      ]
      const legendData = []
      const seriesData = []
      for (let i = 0; i < count; i++) {
        const name =
      Math.random() > 0.65
        ? makeWord(4, 1) + '·' + makeWord(3, 0)
        : makeWord(2, 1)
        legendData.push(name)
        seriesData.push({
          name: name,
          value: Math.round(Math.random() * 100000)
        })
      }
      return {
        legendData: legendData,
        seriesData: seriesData
      }
      function makeWord(max, min) {
        const nameLen = Math.ceil(Math.random() * max + min)
        const name = []
        for (let i = 0; i < nameLen; i++) {
          name.push(nameList[Math.round(Math.random() * nameList.length - 1)])
        }
        return name.join('')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard{
padding: 15px;
.top{
  .toal{
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding:0;
    li{
      list-style: none;
      text-align: center;
    }
    .yuan{
        width: 100px;
        height: 100px;
        border-radius: 50% ;
        border: 2px solid #309830;
        text-align: center;
        line-height: 100px;
    }
    .text{
      font-size: 18px;
    }
  }
.box-card{
  height: 440px;
}
}
}
</style>
